<?php
namespace Index\Controller;
use Think\Controller;
class QuestionController extends CommonController {
    public function indexAction(){

    	$id= I('get.id','');

    	if(!empty($id)){

    		$this->autoadd('question','view',$id);
    		// 获取用户数据
    		$sql = "select t1.*,t2.username from question t1 left join user t2 on t1.uid=t2.id  where t1.id='{$id}'";
    		$question = M()->query($sql);

    		$question = current($question);

    		$question['content'] = htmlspecialchars_decode($question['content']);
    		$question['create_time'] = Ftime(date('Y-m-d H:i:s',$question['create_time']));


    		// 获取当前问题的分类数据
    		$sql = "select t1.cname,t1.id from category t1 left join category_question t2 on t1.id=t2.cid where t2.qid='{$id}'";

    		$category = M()->query($sql);


    		// var_dump($question);exit;
    		$this->assign('category',$category);

    		$this->assign('question',$question);

    		$this->display();

    	}else{
    		$this->error('非法请求',U('index/index/index'));
    	}	
    }
}